const Controller = require('egg').Controller;

class UsersController extends Controller {

  // method : index , new , show , edit , create , update , destroy


  // router: /api/v1/users
  async index() {
    // 请求 orm model操作
    const users = await this.ctx.model.User.findAll({
      limit: 10,
      offset: 0,
      order: [
        [ 'id', 'desc' ],
      ],
    });
    this.ctx.body = users;
  }


  async show() {
    const id = parseInt(this.ctx.params.id) || 1;
    const user = await this.ctx.model.User.findBypK(id);

    this.ctx.body = user;
  }


}

// 老忘记这句话
module.exports = UsersController;
